disp "Renaming Midline Variables"
rename rid idno

rename s3 in_business
rename s3b1 business_type

* Consumption variables
    egen adult_meals = rowmean(s15b_*)
    egen child_meals = rowmean(s15a_*)
    egen all_meals = rowmean(s15*)
    * Need to recheck what it looks like was included in "cereals"
    egen c_cereals = rowtotal(s16a_1-s16a_7) 
    label var c_cereals "s16a_1: maize, potato, millet, etc."
    egen c_meat=rowtotal(s16a_12 s16a_13)
    rename s16a_1  c_maize
    rename s16a_2  c_sorghum
    rename s16a_3  c_millet
    rename s16a_4  c_potato
    rename s16a_5  c_sweetpotato
    rename s16a_6  c_rice
    rename s16a_7  c_bread
    rename s16a_8  c_beans
    rename s16a_9  c_oil
    rename s16a_10 c_salt
    rename s16a_11 c_sugar
    rename s16a_12 c_livestock
    rename s16a_13 c_poultry
    rename s16a_14 c_fish
    rename s16a_15 c_egg
    rename s16a_16 c_nuts
    rename s16a_17 c_milk
    rename s16a_18 c_vegetables
    rename s16a_19 c_fruit
    rename s16a_20 c_tea
    rename s16a_21 c_spices
    rename s16a_22 c_alcohol
    rename s16a_23 c_otherfood

    rename s18a_1 c_fuel 
    rename s18a_2 c_medicine 
    rename s18a_3 c_airtime 
    rename s18a_4 c_cosmetics
    rename s18a_5 c_soap
    rename s18a_6 c_transport
    rename s18a_7 c_entertainment
    rename s18a_8 c_childcare
    rename s18a_9 c_tobacco 
    rename s18a_10 c_batteries
    rename s18a_11 c_durables
    rename s18a_12 c_othermonth

    rename s18b_1  c_clothesfootwear 
    rename s18b_2  c_womensclothes
    rename s18b_3  c_childrensclothes
    rename s18b_4  c_shoes
    rename s18b_5  c_homeimprovement
    rename s18b_6  c_utensils
    rename s18b_7  c_furniture
    rename s18b_8  c_textiles
    rename s18b_9  c_ceremonies
    rename s18b_10 c_funerals
    rename s18b_11 c_charities
    rename s18b_12 c_dowry
    rename s18b_13 c_other

* Shocks, food security, & Conflict
    rename s20a_1 shock_illness
    rename s20b_1 shock_illness_months
    rename s20c_1 shock_illness_ssp
    rename s20d_1 shock_illness_cope
    rename s20a_2 shock_theft
    rename s20b_2 shock_theft_months
    rename s20c_2 shock_theft_ssp
    rename s20d_2 shock_theft_cope
    rename s20a_3 shock_livestock
    rename s20b_3 shock_livestock_months
    rename s20c_3 shock_livestock_ssp
    rename s20d_3 shock_livestock_cope
    rename s20a_4 shock_other
    rename s20b_4 shock_other_months
    rename s20c_4 shock_other_ssp
    rename s20d_4 shock_other_cope
    rename s21_1 fs_worried
    rename s21_2 fs_notpreferred
    rename s21_3 fs_fewkinds
    rename s21_4 fs_preferrednot
    rename s21_5 fs_portions
    rename s21_6 fs_fewmeals
    rename s21_7 fs_nofood
    rename s21_8 fs_hungry
    rename s21_9 fs_wholeday

    rename s22_1  conflict_worried
    rename s22_2a conflict_worried1
    rename s22_2b conflict_worried2
    rename s22_2c conflict_worried3
    rename s22_3  conflict_affected
    rename s22_4a conflict_affected1
    rename s22_4b conflict_affected2
    rename s22_4c conflict_affected3
    rename s22_5  conflict_foodprice_up
    rename s22_6  conflict_transprice_up
    rename s22_7  conflict_healthprice_up
    rename s22_8  conflict_protectlives
    rename s22_9a conflict_protectassets1
    rename s22_9b conflict_protectassets2
    rename s22_10 conflict_whynotprotect
    
                                                         
** Assets & Savings
    rename s7b_3  asset_val_cows
    rename s7b_4  asset_val_smallanimals
    rename s7b_5  asset_val_chickens
    rename s7b_6  asset_val_ducks
    rename s7b_7  asset_val_plough
    rename s7b_8  asset_val_shed
    rename s7b_9  asset_val_shop
    rename s7b_10 asset_val_radio
    rename s7b_11 asset_val_tv
    rename s7b_12 asset_val_fan
    rename s7b_13 asset_val_mobile
    rename s7b_14 asset_val_chairtables
    rename s7b_15 asset_val_bed
    rename s7b_16 asset_val_bicycle
    rename s7b_17 asset_val_carts
    rename s7b_18 asset_val_sewing
    rename s7b_19 asset_val_net
    rename s7b_21 asset_val_charcoal
    rename s7b_22 asset_val_pangas
    rename s7b_23 asset_val_axes
    rename s7b_24 asset_val_ploughs_again
    rename s7b_25 asset_val_stoves
    rename s7b_26 asset_val_potspans
    rename s7b_27 asset_val_motorcycle
    rename s7a_1  asset_n_house
    rename s7a_2  asset_n_homestead
    rename s7a_3  asset_n_cows
    rename s7a_4  asset_n_smallanimals
    rename s7a_5  asset_n_chickens
    rename s7a_6  asset_n_ducks
    rename s7a_7  asset_n_plough
    rename s7a_8  asset_n_shed
    rename s7a_9  asset_n_shop
    rename s7a_10 asset_n_radio
    rename s7a_11 asset_n_tv
    rename s7a_12 asset_n_fan
    rename s7a_13 asset_n_mobile
    rename s7a_14 asset_n_chairtables
    rename s7a_15 asset_n_bed
    rename s7a_16 asset_n_bicycle
    rename s7a_17 asset_n_carts
    rename s7a_18 asset_n_sewing
    rename s7a_19 asset_n_net
    rename s7a_21 asset_n_charcoal
    rename s7a_22 asset_n_pangas
    rename s7a_23 asset_n_axes
    rename s7a_24 asset_n_ploughs_again
    rename s7a_25 asset_n_stoves
    rename s7a_26 asset_n_potspans
    rename s7a_27 asset_n_motorcycle

    rename s6a land_owncult        
    rename s6b land_ownnocult
    rename s6c land_ownrent
    rename s6d land_rentcult
    rename s6e land_communitycult

    rename s8aa savings_home
    rename s8ab savings_bank
    rename s8ac savings_BRAC
    rename s8ad savings_NGOs
    rename s8ae savings_other

    rename s8b_1a savings_maize_q
    rename s8b_2a savings_maize_val
    rename s8b_1b savings_sorghum_q
    rename s8b_2b savings_sorghum_val
    gen savings_cassava_q=.
    gen savings_cassava_val=.
    gen savings_beans_q =.
    gen savings_beans_val =.
    replace savings_cassava_q=s8b_1c if s8bcoth==9
    replace savings_cassava_val=s8b_2c if s8bcoth==9
    replace savings_beans_q=s8b_1c if s8bcoth==6
    replace savings_beans_val=s8b_2c if s8bcoth==6

** Transfers

    rename s101    transfers_any_get
    rename s102    transfers_any_give
    rename s101_c1 transfers_get1
    rename s101_c2 transfers_get2
    rename s101_c3 transfers_get3
    rename s102_c1 transfers_give1
    rename s102_c2 transfers_give2
    rename s102_c3 transfers_give3

** Confidence & Autonomy

    rename s5a access_healthcenter
    rename s5b access_loans
    rename s5c access_enrollchild
    rename s5d access_foodtransfer
    rename s5e access_coops

    rename s9_1 decide_moneyown
    rename s9_2 decide_healthown
    rename s9_3 decide_majorpurchase
    rename s9_4 decide_dailypurchase
    rename s9_5 decide_familyvisits
    rename s9_6 decide_healthchild
    rename s9_7 decide_pressuretospend
    rename s9_8 decide_arguments
    rename s9_9 decide_fearful

    rename s11_1 conf_business
    rename s11_2 conf_credit
    rename s11_3 conf_finances
    rename s11_4 conf_buybargain
    rename s11_5 conf_sellbargain
    rename s11_6 conf_save

    rename s25a_1 gone_market
    rename s25a_2 gone_school
    rename s25a_3 gone_healthcenter
    rename s25a_4 gone_houserelative
    rename s25a_5 gone_housenonrelative
    rename s25a_6 gone_NGO
    rename s25a_7 gone_water
    rename s25a_8 gone_church
    rename s25b_1 cango_market
    rename s25b_2 cango_school
    rename s25b_3 cango_healthcenter
    rename s25b_4 cango_houserelative
    rename s25b_5 cango_housenonrelative
    rename s25b_6 cango_NGO
    rename s25b_7 cango_water
    rename s25b_8 cango_church


** Appending _m tag to specify these are midline variables
** This is not elegant, but it's what I've been doing so far. Will probably make more sense later on to just append the data
foreach variable of varlist * {
    rename `variable' `variable'_m
    }
    rename cln_m cln 
    rename idno_m idno 
    *rename res_m res

